<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <div id="app">
    <p>事件绑定</p>
    <button v-on:click="isLogin = !isLogin">登录1</button>
    <button v-on:click="loginToggle">登录2</button>
    <p>登录状态：{{isLogin?'':'未'}}登录</p>
    <hr>
    <button @click="say('你好')">说话</button>
    <button @click="say('再见')">说话</button>
    <hr>
    <p>自定义参数：</p>
    <input type="text" placeholder="请输入充值金额" v-model="money">
    <button @click="charge(money, '$')">充值</button>
    <hr>
    <p>事件对象：</p>
    <button @click="getEvent($event)">点击</button>
    <input type="text" @input="getEvent($event)">
    <hr>
    <input type="text" v-model="val" @input="getAllData(val, $event)">
    <hr>
    <hr>
    <hr>
    <!-- <input type="text" v-model="val2"> -->
    <p>v-model是语法糖，是v-on和v-bind的缩写。v-on监听视图，v-bind监听数据，二者结合就是双向绑定，数据驱动视图更新。</p>
    <input type="text" @input="model" :value="val2">
    <p>{{val2}}</p>
  </div>
  <script src="../vue.js"></script>
  <script>
    let vm = new Vue({
      el: '#app',
      data: {
        isLogin: false,
        money: 1,
        val: '',
        val2: ''
      },
      methods: {
        // 模拟实现v-model的功能
        model(e) {
          this.val2 = e.target.value;
        },
        loginToggle(e) {
          // 隐式传递
          console.log(e);
          this.isLogin = !this.isLogin;
        },
        say(text) {
          alert(text)
        },
        charge(num, type) {
          alert('不充值你会变强吗？');
          alert(type+num);
        },
        getEvent(e) {
          // 显式传递
          console.log(e);
        },
        getAllData(val, e) {
          console.log('自定义参数：', val);
          console.log('事件对象：', e);
        }
      },
    })
  </script>
</body>
</html>